package com.sync.data.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    /**
     * 使用@Primary标记主数据源；主数据源只能有一个
     * @return
     */
    @Primary
    @Bean(name = "ieventDataSource")
    @Qualifier("ieventDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.ievent")
    public DataSource ieventDataSource() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "mceDataSource")
    @Qualifier("mceDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.mce")
    public DataSource mceDataSource() {
        return DataSourceBuilder.create().build();
    }

}
